class_name Player
extends CharacterBody2D

@export var weapon: Equipment

var face_direction: float = 1.0

@onready var asc: AbilitySystemComponent = %AbilitySystemComponent

@onready var animator: AnimatedSprite2D = %Animator

@onready var state_machine: PlayerStateMachine = %StateMachine

@onready var input_handler: PlayerInputHandler = %InputHandler

@onready var state_checker: PlayerStateChecker = %StateChecker


func flip() -> void:
	face_direction = -face_direction
	scale.x = -scale.x


func _ready() -> void:	
	asc.logic_owner = self
	
	weapon.on_attach(asc)


func _process(_delta: float) -> void:
	# print(asc.tag_manager.get_all_tags())

	move_and_slide()


#region Helper Functions
#region Animator
func play_animation(animation_name: String) -> void:
	animator.play(animation_name)


func stop_animation() -> void:
	animator.stop()
#endregion


#region Gameplay Attribute 
func get_attribute(attribute_name: String) -> GameplayAttribute:
	return asc.attribute_set.get_attribute(attribute_name)
#endregion


#region Gameplay Tag
func add_tag(tag: String) -> void:
	asc.tag_manager.add_tag(tag)


func add_tags(tags: Array[String]) -> void:
	asc.tag_manager.add_tags(tags)


func remove_tag(tag: String) -> void:
	asc.tag_manager.remove_tag(tag)


func remove_tags(tags: Array[String]) -> void:
	asc.tag_manager.remove_tags(tags)


func has_tag(tag: String) -> bool:
	return asc.tag_manager.has_tag(tag)


func has_any_tags(tags: Array[String]) -> bool:
	return asc.tag_manager.has_any_tags(tags)


func has_all_tags(tags: Array[String]) -> bool:
	return asc.tag_manager.has_all_tags(tags)


func get_all_tags() -> Array[String]:
	return asc.tag_manager.get_all_tags()
#endregion


#region Gameplay Ability
func grant_ability(ability_asset: GameplayAbilityAsset) -> void:
	asc.ability_manager.grant_ability(ability_asset)


func grant_abilities(ability_assets: Array[GameplayAbilityAsset]) -> void:
	asc.ability_manager.grant_abilities(ability_assets)


func try_apply_ability(ability_asset: GameplayAbilityAsset, target: AbilitySystemComponent) -> void:
	asc.ability_manager.try_apply_ability(ability_asset, target)


func try_apply_ability_to_self(ability_asset: GameplayAbilityAsset) -> void:
	try_apply_ability(ability_asset, asc)


func remove_ability(ability_asset: GameplayAbilityAsset) -> void:
	asc.ability_manager.remove_ability(ability_asset)


func activate_ability(ability_asset: GameplayAbilityAsset) -> void:
	asc.ability_manager.activate_ability(ability_asset)
	

func deactivate_ability(ability_asset: GameplayAbilityAsset) -> void:
	asc.ability_manager.deactivate_ability(ability_asset)
#endregion
#endregion
